/* open-file-dialog.vala
 *
 * Copyright (C) 2010  Richard Talbot-Watkins
 * Copyright (C) 2010  Dave Jeffery
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Authors:
 *  Richard Talbot-Watkins <richtw1@gmail.com>
 * 	Dave Jeffery <david.richard.jeffery@gmail.com>
 */

using Gtk;

/**
 * Open file chooser dialog box.
 *
 * @author Dave Jeffery <david.richard.jeffery@gmail.com>
 * @version 2010.1214
 * @since 0.1
 */    
private class MonsterDesigner.OpenFileDialog : FileChooserDialog {
	/**
	 * Constructor for the open file dialog box.
	 *
	 * @param file path of the folder to display in file chooser
	 */ 
	public OpenFileDialog (File file) {
		title = "Open";
		action = FileChooserAction.OPEN;

		add_button (STOCK_CANCEL, ResponseType.CANCEL);
		add_button (STOCK_OPEN, ResponseType.ACCEPT);
		set_default_response (ResponseType.ACCEPT);

		if (file.query_exists () && 
				file.query_file_type (0) != FileType.DIRECTORY) {
			try {
				set_current_folder_file (file.get_parent ());
			} catch (Error e) {
				stderr.printf ("%s\n", e.message);
			}
		} else {
			var path = File.new_for_path (Environment.get_user_special_dir 
											(UserDirectory.DOCUMENTS));
			try {
				set_current_folder_file (path);
			} catch (Error e) {
				stderr.printf ("%s\n", e.message);
			}
		}
	}
}
